package dao;

import beans.User;
import cn.hutool.crypto.digest.DigestUtil;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import utils.JDBCUtils;

import java.sql.SQLException;

/**
 * ClassName: UserDao
 * Package: dao
 * Description:
 *
 * @Author 刘英杰
 * @Create 2024/10/7 10:09
 * @Version 1.0
 */
public class UserDao {
    public User login(User user) {
        QueryRunner qr = new QueryRunner(JDBCUtils.getDataSource());
        User existUser = null;
        try {
            existUser = qr.query("SELECT * FROM `user` WHERE username=? AND password=?",
                    new BeanHandler<User>(User.class),user.getUsername(), DigestUtil.md5Hex(user.getPassword()));
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return existUser;
    }
}
